package info.xiao.dataStructrue.array;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Classname Generate
 * @Description 杨辉三角形
 * @Url https://leetcode.cn/problems/pascals-triangle/
 * @Date 2023/4/13 10:59
 * @Created by 晓龙Oba
 */
public class Generate {
    public static void main(String[] args) {
        int numRows = 5;
        List<List<Integer>> result = generate(numRows);
        System.out.println(result);
    }

    private static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> lists = new ArrayList<>();

        for (int i = 0; i < numRows; i++) {
            List<Integer> integers = new ArrayList<>(Collections.nCopies(i + 1, null));
            lists.add(integers);
            integers.set(0, 1);
            integers.set(i, 1);
            if (i < 2) {
                continue;
            }
            List<Integer> front = lists.get(i - 1);
            for (int j = 1; j < i; j++) {
                Integer a = front.get(j);
                Integer b = front.get(j - 1);
                integers.set(j, a + b);
            }
        }
        return lists;
    }
}
